<?php
require __dir__ . '/bootstrap.php';
$em = require __dir__ . '/example/em.php';

require_once('lib/PHPMailer_5.2.4/class.phpmailer.php');

$mail = new PHPMailer(); // defaults to using php "mail()"

if (isset($_POST['name'])){
    $name= $_POST['name'];
}
if (isset($_POST['user_email'])){
    $user_email= $_POST['user_email'];
}
if (isset($_POST['text'])) {
    $body = "Сообщение от пользователя: ". $name . "\n";
    $body .= "E-mail: ".$user_email. "\n";
    $body .= $_POST['text'];
}

$mail->AddReplyTo($user_email, "");

$mail->SetFrom($user_email, '');

$mail->AddReplyTo($user_email, "");

//Кому
$address = 'partners@smart-sim.ru';
//$address = 'kerch@inbox.ru';

// Скрытая копия
$mail->AddBCC('makerra@gmail.com');
//$mail->AddBCC('kerch@inbox.ru');

//Кому
$mail->AddAddress($address);
$mail->Subject = "Агентское обращение на Agent SmartSim";


//$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->CharSet = 'UTF-8';
$mail->ContentType = 'text/plain';
$mail->IsHTML(false);
$mail->Body = $body;
//$mail->AddAttachment("lib/PHPMailer_5.2.4/examples/images/phpmailer.gif");      // attachment
//$mail->AddAttachment("lib/PHPMailer_5.2.4/examples/images/phpmailer_mini.gif"); // attachment

if (!$mail->Send()) {
    echo '{ "message": "Ошибка! ' . $mail->ErrorInfo . '", "type": "st-error" }';
} else {
    echo '{ "message": "Ваше сообщение отправлено!", "type": "st-success" }';
}

?>